home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 April / MacFormat CD Edition MF36 (April 1996).iso / Shareware City / Comms / TableMaker ƒ / TableMaker / TableMaker.rsrc / TEXT_128_!.txt < prev    next >
Encoding:
Text File  |  1996-01-22  |  6.6 KB  |  234 lines

  1. #!/usr/bin/perl
  2.  
  3. ############################################################################
  4. #
  5. # TableMaker by Sam Choukri 
  6. # Copyright 1995, 1996 
  7. # version 1.0.1
  8. # January 22, 1996
  9. #
  10. # If you want to redistribute TableMaker, please include ALL the files in
  11. # their ORIGINAL STATE, including the Runtime or Droplet version of the
  12. # TableMaker application, documentation, and the default settings file. Do
  13. # not under any circumstances redistribute just this file -- the actual
  14. # TableMaker MacPerl script.
  15. #
  16. # You can modify this script to suit your needs, but do not redistribute
  17. # your modified copy. I don't claim to be a good Perl programmer. If you
  18. # make changes that improves the efficiency or adds new features, send me
  19. # a copy of the modified script and I'll consider incorporating the changes
  20. # into the next released version of TableMaker.
  21. #
  22. # Remember, TableMaker is shareware. If you feel it has been helpful to
  23. # you, please send five US dollars to:
  24. #     Sam Choukri
  25. #     406 Tucker Hall, UMC
  26. #     Columbia, MO 65211
  27. # TableMaker started out as a web page and then was converted into a stand
  28. # alone version after popular demand. Check out TableMaker on the web at
  29. # <http://www.missouri.edu/~c588349/tablemaker.html>.
  30. # You can send me e-mail at <sam@pobox.com> if you'd like.
  31. #
  32. ############################################################################
  33.  
  34.  
  35. # check to see if there were any files dropped on TableMaker
  36. if (@ARGV == 0) {&MacPerl'Answer("To use TableMaker, you need to drag and drop one or more data files onto it.\n\nPlease quit and try again.", "Quit");
  37. &MacPerl'Quit(1); # automatically quits MacPerl Runtime version
  38. exit;
  39. }
  40.  
  41. ###################################################
  42. # these are the required functions from "GUSI.ph"
  43.  
  44. sub AF_FILE         { 4;    }
  45. sub pack_sa_constr_file    {
  46.     local($count, $constr, $cur) = (0, "");
  47.     
  48.     while ($cur = shift) {
  49.         ++$count;
  50.         $constr .= pack("A4", $cur);
  51.     }
  52.     
  53.     pack("s", $count) . $constr;
  54. }
  55. ###################################################
  56.  
  57. $settingsfile = &MacPerl'Choose(
  58.                &AF_FILE, 0, "Select a settings file:", 
  59.                &pack_sa_constr_file("TEXT"));
  60.  
  61.  
  62. require "$settingsfile";
  63.  
  64. if (($BOLD_CAPTION eq 'YES') && ($CAPTION ne '')) { $CAPTION = "<B>" . $CAPTION . "<\/B>";}
  65.  
  66.  
  67.     while (@ARGV > 0) {
  68.         $arg = shift(@ARGV);
  69.         &find($arg), next if -d $arg;
  70.         &searchLoop($arg);
  71.         next if -f $arg;
  72.  
  73.     }
  74.  
  75. sub searchLoop {
  76. local ($thefilename) = @_;
  77.  
  78. # create an output html file and start printing to it
  79. # but first make sure the output filename won't exceed 31 chars
  80. # -------------------------------------------------------------
  81. @temp = split(/:/,$thefilename);
  82. while (length($temp[$#temp]) > 26) {chop $temp[$#temp];}
  83. $outputfile = join(':', @temp) . ".html";
  84. open(OUTPUT, ">".$outputfile) || die "Can't write to file\n";
  85. &MacPerl'SetFileInfo($CREATOR, "TEXT", $outputfile) ;
  86.  
  87. print OUTPUT <<ENDOFTEXT;
  88. <HTML>
  89. <HEAD><title>TableMaker Output</title></HEAD>
  90. <BODY>
  91.  
  92. <H1>TableMaker Output</H1>
  93.  
  94. ENDOFTEXT
  95.  
  96. $/ = "";                    # enable paragraph mode for input
  97. $* = 1;                     # enable multi-line patterns for search/replace
  98.  
  99. open(THEFILE, $thefilename) || die "Can't open file $thefilename\n";
  100. while ($data = <THEFILE>) {
  101.  
  102.  
  103. # by default, format all cells as data cells
  104. # ------------------------------------------
  105. $data =~ s/((\r)+)/\n/g;
  106. $data =~ s/((\n)+)/\n/g;
  107. $data =~ s/^(.*)$/<TR>\n  <TD>$1<\/TD>\n<\/TR>/g;
  108. $data =~ s/$DELIMITER/<\/TD>\n  <TD>/go;
  109.  
  110.  
  111.  
  112. $HEADER =~ tr/[a-z]/[A-Z]/;  # make sure input is in all caps
  113.  
  114. # change the formatting of the first row to header cells
  115. # ------------------------------------------------------
  116. if (($HEADER eq 'FIRST ROW') || ($HEADER eq 'FIRST ROW AND COLUMN')) {
  117. $data =~ s/((\n)+)//g;
  118. $* = 0;
  119. $data =~ s/<\/TR>(.*)<\/TR>/<\/TR><TEMPORARY_DATA><\/TR>/g;
  120. $TEMPORARY_DATA = $1;
  121. $data =~ s/<TD>/<TH>/g;
  122. $data =~ s/<\/TD>/<\/TH>/g;
  123. $data =~ s/<TEMPORARY_DATA>/$TEMPORARY_DATA/g;
  124. $* = 1;
  125. $data =~ s/<TR>/<TR>\n/g;
  126. $data =~ s/<\/T([DHR])>/<\/T$1>\n/g;
  127. $data =~ s/<\/TR>(\n)+/<\/TR>\n/g;
  128. }
  129.  
  130.  
  131. # change the formatting of the first column to header cells
  132. # ---------------------------------------------------------
  133. if (($HEADER eq 'FIRST COLUMN') || ($HEADER eq 'FIRST ROW AND COLUMN')) {
  134. $data =~ s/<TR>\n  <TD>(.*)<\/TD>/<TR>\n  <TH>$1<\/TH>/g;
  135. }
  136.  
  137.  
  138. # change the formatting of all cells to header cells
  139. # --------------------------------------------------
  140. if ($HEADER eq 'ALL CELLS') {
  141. $data =~ s/<TD>/<TH>/g;
  142. $data =~ s/<\/TD>/<\/TH>/g;
  143. }
  144.  
  145.  
  146. # look for row and column spanning codes
  147. # --------------------------------------
  148. $SPANNING =~ tr/[a-z]/[A-Z]/;  # make sure input is in all caps
  149. if ($SPANNING eq 'YES') {
  150. $data =~ s/<T([DH])>\(colspan=([\d]*)\)/<T$1 COLSPAN=$2>/gi;
  151. $data =~ s/<T([DH])>\(cs=([\d]*)\)/<T$1 COLSPAN=$2>/gi;
  152. $data =~ s/<T([DH])>\(rowspan=([\d]*)\)/<T$1 ROWSPAN=$2>/gi;
  153. $data =~ s/<T([DH])>\(rs=([\d]*)\)/<T$1 ROWSPAN=$2>/gi;
  154. }
  155.  
  156. # specify the horiz alignment for all cells in a row
  157. # --------------------------------------------------
  158. $ROW_ALIGN =~ tr/[a-z]/[A-Z]/;  # make sure input is in all caps
  159. if ($ROW_ALIGN ne 'DEFAULT') {
  160. $data =~ s/<TR>/<TR ALIGN=$ROW_ALIGN>/g;
  161. }
  162.  
  163. # specify the horiz alignment for all data cells
  164. # ----------------------------------------------
  165. $TD_ALIGN =~ tr/[a-z]/[A-Z]/;  # make sure input is in all caps
  166. if ($TD_ALIGN ne 'DEFAULT') {
  167. $data =~ s/<TD/<TD ALIGN=$TD_ALIGN/g;
  168. }
  169.  
  170. # specify the horiz alignment for all header cells
  171. # ------------------------------------------------
  172. $TH_ALIGN =~ tr/[a-z]/[A-Z]/;  # make sure input is in all caps
  173. if ($TH_ALIGN ne 'DEFAULT') {
  174. $data =~ s/<TH/<TH ALIGN=$TH_ALIGN/g;
  175. }
  176.  
  177.  
  178. # choose how the table source is formatted
  179. # ----------------------------------------
  180. $SOURCE_LINES =~ tr/[a-z]/[A-Z]/;  # make sure input is in all caps
  181. if ($SOURCE_LINES eq 'SAME') {
  182. $data =~ s/<\/T([DH])>\n  \<T([DH])/<\/T$1> \<T$2/g;
  183. }
  184.  
  185.  
  186. # build table tags
  187. # ----------------
  188. $TABLE = "<TABLE";
  189. if ($BORDER ne '') {$TABLE .= " BORDER=$BORDER";}
  190. if ($WIDTH ne '') {$TABLE .= " WIDTH=\"$WIDTH\"";}
  191. if ($HEIGHT ne '') {$TABLE .= " HEIGHT=\"$HEIGHT\"";}
  192. if ($CELLPADDING ne '') {$TABLE .= " CELLPADDING=$CELLPADDING";}
  193. if ($CELLSPACING ne '') {$TABLE .= " CELLSPACING=$CELLSPACING";}
  194. $TABLE .= ">\n";
  195. if ($CAPTION ne '') {$TABLE .= "<CAPTION ALIGN=$ALIGN_CAPTION>$CAPTION</CAPTION>\n";}
  196. $TABLE .= $data;
  197. $TABLE .= "\n</TABLE>";
  198.  
  199.  
  200. # print the source of each table in the html file
  201. # -----------------------------------------------
  202. print OUTPUT <<ENDOFTEXT;
  203. <HR>
  204.  
  205. <!--BEGIN SOURCE OF TABLE-->
  206. $TABLE
  207. <!--END SOURCE OF TABLE-->
  208.  
  209. ENDOFTEXT
  210.  
  211. } # end while
  212.  
  213.  
  214. print OUTPUT <<ENDOFTEXT;
  215. </BODY>
  216. </HTML>
  217. ENDOFTEXT
  218.  
  219. close(OUTPUT);
  220.  
  221. } # end searchLoop
  222.  
  223. &MacPerl'Answer("Job complete.\n\nThanks for using TableMaker.", "OK");
  224.  
  225. &MacPerl'Quit(1); # automatically quits MacPerl Runtime version
  226.  
  227. exit;
  228.  
  229.  
  230.  
  231.